package com.example.ccj.b.c.custom.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;


import com.example.ccj.R;
import com.example.ccj.b.c.custom.image.MLocalMedia;
import com.example.ccj.b.c.custom.image.PhotoView;
import com.example.ccj.b.c.custom.image.ShowBigPictureControl;
import com.example.ccj.u.ImageUtils;

import java.util.List;

/**
 * 图片轮播viewpager的adpater
 * 例子：viewPager.setAdapter(new AdpaterForBigPhotoViewPager(PageBigPhotoAndViewPagerActivity.this,dd));
 * 2022年10月20日18:30:38
 */
public class AdapterForBigPhotoViewPager extends PagerAdapter {
    private Context mContext;
    private List<MLocalMedia> myImages;

    private boolean isShowBottomList = true;

    ShowBigPictureControl.ShowAndHidePictureListener showAndHidePictureListener;

    public AdapterForBigPhotoViewPager(Context mContext, List<MLocalMedia> myImages, ShowBigPictureControl.ShowAndHidePictureListener showAndHidePictureListener){
//        myLog.d("图片轮播控件，当前的图片是类型是","设置view pager");
        this.mContext = mContext;
        this.myImages = myImages;
        this.showAndHidePictureListener = showAndHidePictureListener;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View)object);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = View.inflate(mContext, R.layout.adpter_big_photo_view_pager,null);
        PhotoView imageView = view.findViewById(R.id.iv_banner);
        imageView.enable();

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isShowBottomList = !isShowBottomList;
                showAndHidePictureListener.onCallBack(isShowBottomList);
            }
        });
        ImageUtils.loadImage(mContext,myImages.get(position).getAvailablePath(),imageView);
        container.addView(view);


        return view;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public int getCount() {
        return myImages.size();
    }

}
